ohibc logo
OHI British Columbia | OHI Science | Citation policy

knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.path = 'Figs/',
                      echo = TRUE, message = FALSE, warning = FALSE)

library(data.table)
library(seaaroundus) ### devtools::install_github("ropensci/seaaroundus")
library(raster)

dir_git <- '~/github/ohibc'
source(file.path(dir_git, 'src/R/common.R'))  ### an OHIBC specific version of common.R
dir_spatial <- path.expand(file.path(dir_git, 'prep/_spatial'))  ### github: general buffer region shapefiles
dir_anx     <- file.path(dir_M, 'git-annex/bcprep')


### goal specific folders and info
goal      <- 'fis'
scenario  <- 'v2017'
dir_goal  <- file.path(dir_git, 'prep', goal, scenario)
dir_goal_anx <- file.path(dir_anx, goal, scenario)

### provenance tracking
library(provRmd); prov_setup()

### set up proj4string options: BC Albers and WGS84
p4s_wgs84 <- '+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0'
p4s_bcalb <- '+proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0'

1 Plot all SAUP data in BC region

For each taxa found in the BC extents (not necessarily in OHIBC regions), summarize total catch across all years and plot against a map of BC to identify which taxa are actually reported in the BC EEZ.

saup_base_rast <- raster::raster(file.path(dir_goal, 'saup/2_saup_bc_rast.tif'))

ohibc_sf <- sf::read_sf(dir_spatial, 'ohibc_rgn') %>%
  sf::st_transform(crs(saup_base_rast, asText = TRUE))

plot_taxon <- function(saup_df) {
  ### saup_df <- saup_sum %>% filter(taxon_key == first(taxon_key))
  taxon_sciname <- saup_df$taxon_scientific_name[1]
  taxon_comname <- saup_df$taxon_common_name[1]
  taxon_rast <- subs(saup_base_rast, saup_df, by = 'cell_id', which = 'catch')
  
  taxon_pts <- rasterToPoints(taxon_rast) %>%
    as.data.frame()
  
  taxon_plot <- ggplot() +
    ggtheme_plot() +
    geom_raster(data = taxon_pts, 
                aes(x = x, y = y, fill = layer), 
                alpha = .6) +
    geom_sf(data = ohibc_sf, color = 'grey30', fill = NA) +
    scale_fill_distiller(palette = 'Spectral') +
    theme(axis.title = element_blank()) +
    labs(fill = 'catch',
         title = paste0(taxon_sciname, ': ', taxon_comname))
  
  return(taxon_plot)
}
saup_raw <- read_csv(file.path(dir_goal_anx, 'saup/2_saup_bc_raw.csv'))

saup_sum <- saup_raw %>%
  group_by(cell_id, taxon_key) %>%
  summarize(catch = sum(catch_sum, na.rm = TRUE)) %>%
  ungroup() %>%
  left_join(read_csv(file.path(dir_goal, 'saup/2_taxon_keys_allbc.csv')),
            by = 'taxon_key')

taxa_ids <- saup_sum$taxon_key %>%
  unique() %>%
  sort(decreasing = TRUE)

for(taxon_id in taxa_ids) {
  ### taxon_id <- taxa_ids[2]
  saup_df <- saup_sum %>%
    filter(taxon_key == taxon_id)
  
  message('generating plot for ', 
          saup_df$taxon_scientific_name[1], 
          ': ', 
          saup_df$taxon_common_name[1])

  taxon_plot <- plot_taxon(saup_df)
  
  print(taxon_plot)
}


prov_wrapup(commit_outputs = FALSE)

2 Provenance

  • Run ID: 2 (f2a1442); run tag: “standard run”
  • Run elapsed time: 835.27 seconds; run memory usage: 84993.5 MB
  • System info:
    • System: Linux, Release: 4.4.0-57-generic. Machine: x86_64. User: ohara.
    • R version: R version 3.4.1 (2017-06-30), Platform: x86_64-pc-linux-gnu, Running under: Ubuntu 14.04.5 LTS.
    • Attached base packages: stats, graphics, grDevices, utils, datasets, methods, base
    • Other attached packages: provRmd_0.1.1, stringr_1.2.0, RColorBrewer_1.1-2, dplyr_0.5.0, purrr_0.2.2, readr_1.1.0, tidyr_0.6.2, tibble_1.3.3, ggplot2_2.2.1.9000, tidyverse_1.1.1, raster_2.5-8, sp_1.2-5, seaaroundus_1.0.1.9157, data.table_1.10.4
%3 4 2_saup_bc_raw.csv 2 2a_plot_saup.Rmd#plot_all_saup 4->2 used 5 2_taxon_keys_allbc.csv 5->2 used 1 2a_plot_saup.Rmd 1->2 wasExecutedBy 3 2a_plot_saup.Rmd#provenance 1->3 wasExecutedBy